<?php

class CArticleClass extends systemBase {
	private $lrSettings;

	public function __construct($lsModuleName) {
		parent::__construct($lsModuleName);
		//$lrSettings = $this->Model->getArticlesSettings();
	}

	public function actionList() {
		$ltArticles = $this->Model->getLastAricles(5);
		$this->Smarty->assign("articles", $ltArticles);
	}

	public function actionRead() {
		$lnIDArticle = (int)getGet("id");
		$lrArticle = $this->Model->GetArticle($lnIDArticle);
		// kontroly
		if(isset($lrArticle["IDARTICLE"])) {
			if($lrArticle["STATUS"] != "PUBLISHED") {
				$this->AddError("Tento článek není publikován");
				$lrArticle = NULL;
			}
		}
		else {
			$this->AddError("Tento článek neexistuje");
		}
		$this->Smarty->assign("article",$lrArticle);
	}

	public function actionNew() {
		if(IsFormSent("create")) {
			$lsPerex = getPost("perex");
			$lsContent = getPost("content");
			//
			if($lsPerex == "<br>") {
				$this->AddError("Perex je prázdný!");
			}
			//
			if(!$this->IfError()) {
				$this->Model->CreateArticle($lsPerex, $lsContent, "NEW");
				$this->AddError("Created!");
			}
		}
	}

}

?>
